package com.atguigu.gulimall.order.controller;

import com.atguigu.gulimall.order.entity.OrderReturnReasonEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
public class RabbitController {
    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/sendMq")
    public String sendMq() {
        //测试发消息 如果发送的消息是个对象，我们会使用序列化机制，将对象写出去，所以对象必须要实现Serializable
        OrderReturnReasonEntity orderReturnReasonEntity = new OrderReturnReasonEntity();
        orderReturnReasonEntity.setId(1L);
        orderReturnReasonEntity.setCreateTime(new Date());
        orderReturnReasonEntity.setName("哈哈");
        //2.发送的对象类型消息，可以是一个json
        rabbitTemplate.convertAndSend("hello-java-exchange", "hello.java", orderReturnReasonEntity);
        return "OK";
    }

}
